<?php

require_once 'AbstractService.php';

/**
 * 查询域名是否可注册
 * Class CheckDomainService
 * time 2020/11/11 12:24
 * author zrone <xujining415@gmail.com>
 * copyright zrone <xujining415@gmail.com>
 */
class CheckDomainService extends AbstractService
{
    public function __invoke(string $domainName)
    {
        $logicParams = $this->getLogicParams($domainName);

        $result = $this->terminal($logicParams, 'CheckDomain');
        if (isset($result["Avail"])) {
            return "域名: " . $result["Name"] . " " . ($result["Avail"] == 0 ? ("不可用" . ",原因: " . $result["Reason"]) : "可用");
        } else {
            return "请求失败，请刷新重试!";
        }
    }

    private function getLogicParams(string $domainName) {
        return [
            'DomainName' => $domainName
        ];
    }
}